package com.shaoshaohuo.app.ui;

import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.entity.BaseEntity;
import com.shaoshaohuo.app.net.HttpRequest.RequestListener;
import com.shaoshaohuo.app.net.RequestService;
import com.shaoshaohuo.app.view.TopbarView;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class FeedbackActivity extends BaseActivity {
	private TopbarView mTopbarView;

	private EditText mContentEdit;
	private Button mNextButton;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_feedback);
		initView();
		setUpView();
	}

	private void initView() {
		mTopbarView = (TopbarView) this.findViewById(R.id.topbar);
		mContentEdit = (EditText) this.findViewById(R.id.edittext_phone);
		mNextButton = (Button) this.findViewById(R.id.button_next);
	}

	private void setUpView() {
		mTopbarView.setCenterText("意见反馈");
		mTopbarView.setLeftView(true, true);
		// mTopbarView.setRightText("常见问题");
		// mTopbarView.setRightClickListener(new OnClickListener() {
		//
		// @Override
		// public void onClick(View v) {
		// // TODO Auto-generated method stub
		//
		// }
		// });
		
		mNextButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				feedback();
			}
		});
	}

	protected void feedback() {
		String content = mContentEdit.getText().toString().trim();
		
		if(TextUtils.isEmpty(content)){
			showToast("请输入反馈内容");
			return;
		}
		startLoadingDialog();
		RequestService.getInstance().feedback(this, content, BaseEntity.class, new RequestListener() {
			
			@Override
			public void onSuccess(int requestCode, BaseEntity resultData) {
				dismissLoadingDialog();
				if(resultData.isOk()){
					showToast("提交成功");
					finish();
				}else{
					showToast(resultData.getMsg());
				}
			}
			
			@Override
			public void onFailed(int requestCode, Exception error, String msg) {
				dismissLoadingDialog();
				showToast(R.string.please_check_network);
			}
		});
	}
}
